% loads connectome form given file
function [ connectome, name ] = loadConnectomeFromFile(filePath)
    fileID = fopen(filePath,'r');
    
    line = fgets(fileID); % load name
    line(strfind(line, ':')) = [];
    Key   = 'ConnectomesName';
    Index = strfind(line, Key);
    name = line((Index(1) + length(Key)):(end-1));
    
    line = fgets(fileID); % read input size
    line(strfind(line, ':')) = [];
    Key   = 'InputSize';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    connectome.inputSize = Value;
    
    line = fgets(fileID); % read output size
    line(strfind(line, ':')) = [];
    Key   = 'OutputSize';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    connectome.outputSize = Value;
    
    line = fgets(fileID); % read MaximalNumberOfNeuronsInLayer
    line(strfind(line, ':')) = [];
    Key   = 'MaximalNumberOfNeuronsInLayer';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    connectome.maximalNumberOfNeuronsInLayer = Value;
    
    line = fgets(fileID); % read NumberOfLayers
    line(strfind(line, ':')) = [];
    Key   = 'NumberOfLayers';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    connectome.numberOfLayers = Value;
    
    line = fgets(fileID); % read NeuronInLayerVector
    line(strfind(line, ':')) = [];
    Key   = 'NeuronInLayerVector';
    Index = strfind(line, Key);
    VectorString = line((Index(1) + length(Key)):end);
    connectome.neuronInLayerVector = str2num(VectorString);
    
    %% read neurons
    line = fgets(fileID); % read Neuron number
    line(strfind(line, ':')) = [];
    Key   = 'Neurons';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    NeuronNumber = Value;
    
    for i=1:NeuronNumber
        line = fgets(fileID); % read neuron configuatrion
        line(strfind(line, ':')) = [];
        
        Key   = 'Lay';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        Layer = Value;
        
        Key   = 'Id';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        Id = Value;
        
        Key   = 'Thr';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        Threshold = Value;
        
        connectome.neurons(1,i) = neuron(Id, Layer, Threshold);
    end
    
    %% read synapses
    line = fgets(fileID); % read Synapses number
    line(strfind(line, ':')) = [];
    Key   = 'Synapses';
    Index = strfind(line, Key);
    Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
    SynapsesNumber = Value;
    
    for i=1:SynapsesNumber
        line = fgets(fileID); % read synapse configuatrion
        line(strfind(line, ':')) = [];
        
        Key   = 'InLa';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        InLa = Value;
        
        Key   = 'InId';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        InId = Value;
        
        Key   = 'OuLa';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        OuLa = Value;
        
        Key   = 'OuId';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%i', 1);
        OuId = Value;
        
        Key   = 'W';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        W = Value;
        
        Key   = 'Active';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        Active = Value;
        
        Key   = 'DefTim';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        DefTim = Value;
        
        Key   = 'ReTim';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        ReTim = Value;
        
        Key   = 'InMem';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        InMem = Value;
        
        Key   = 'MemThr';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        MemThr = Value;
        
        Key   = 'DeaThr';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        DeaThr = Value;
        
        Key   = 'WithoutUse';
        Index = strfind(line, Key);
        Value = sscanf(line(Index(1) + length(Key):end), '%g', 1);
        WithoutUse = Value;

        
        connectome.synapses(1,i) = loadSynapse(W, DefTim, ReTim, InId, InLa, OuId, OuLa, Active, InMem, MemThr, DeaThr, WithoutUse);
    end
    
    fclose(fileID);
end

